<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            margin: 40px auto;
        }

        div {
            text-align: center;
            margin-top: 40px;
        }
    </style>

</head>

<body>
    <table width="600" border="1" cellspacing="0" align="center">
        <tbody>
            <tr>
                <td >01</td>
                <td>02</td>
                <td>03</td>
                <td>04</td>
                <td>05</td>
            </tr>
            <tr>
                <td>01</td>
                <td>02</td>
                <td>03</td>
                <td>04</td>
                <td>05</td>
            </tr>
            <tr>
                <td>01</td>
                <td>02</td>
                <td>03</td>
                <td>04</td>
                <td>05</td>
            </tr>
            <tr>
                <td>01</td>
                <td>02</td>
                <td>03</td>
                <td>04</td>
                <td>05</td>
            </tr>
        </tbody>
    </table>
    <div>
        <input type="button" value="开始" id="start">
        <input type="button" value="停止" id="stop">
    </div>

    <script>
        var start = document.getElementById("start");//DOM对象
        var stop = document.getElementById("stop");//DOM对象
        var tb = document.querySelector("tbody");//DOM对象
        var tds = document.querySelectorAll("td");//集合
        var timer;
        start.onclick = function () {
            clearInterval(timer);//先清除上一次的计时器
            timer = setInterval(function () {
                for(var i=0;i<tds.length;i++){
                    tds[i].style.background='skyblue';
                }
                var n = parseInt(Math.random() * tds.length); // [0,19]
                tds[n].style.background = "hotpink";
            }, 100);

        };

        stop.onclick=function(){
            clearInterval(timer);
        };
    </script>

</body>

</html>